#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=8005;
int X[N],Y[N],V[N],n,m,Ans;
int Far(int x,int y) {
    return abs(X[x]-X[y])+abs(Y[x]-Y[y]);
}
signed main() {
    freopen("chess.in","r",stdin);
    freopen("chess.out","w",stdout);
    int Test;
    scanf("%lld",&Test);
    while(Test--) {
        Ans=0;
        scanf("%lld %lld",&n,&m);
        for(int i=1;i<=n;i++) scanf("%lld %lld",&X[i],&Y[i]);
        for(int i=1;i<=n;i++) scanf("%lld",&V[i]);
        for(int i=1;i<=n;i++) {
            for(int j=i+1;j<=n;j++) {
                for(int k=j+1;k<=n;k++) {
                    int pos1=Far(i,j),pos2=Far(j,k),pos3=Far(i,k),val;
                    if(pos1<=pos2 && pos2<=pos3) val=pos2;
                    if(pos3<=pos2 && pos2<=pos1) val=pos2;
                    if(pos2<=pos1 && pos1<=pos3) val=pos1;
                    if(pos3<=pos1 && pos1<=pos2) val=pos1;
                    if(pos1<=pos3 && pos3<=pos2) val=pos3;
                    if(pos2<=pos3 && pos3<=pos1) val=pos3;
                    if(val<=10 || val%(20ll)==3) Ans+=V[i]+V[j]+V[k];
                }
            }
        }
        printf("%lld\n",Ans);
    }
    return 0;
}